"use strict";
layui.define(["layer"], function (exports) {
    let $ = layui.jquery,
        openLayer = {
        /**
         * confirm()函数二次封装
         * @param content
         * @param yesFunction
         */
        confirm: function (content, yesFunction) {
            let options = {skin: "1", icon: 3, title: "提示", anim: "0"};
            layer.confirm(content, options, yesFunction);
        },

        /**
         * 查看
         * @param options
         */
        opneView:function(options){
            var opts = options,
                title=opts.title||"查看",
                url=opts.url,
                value=opts.value,
                width=opts.width||"90%",
                height=opts.height||"90%",
             content=url+"?id="+value+"&op=view";
            openLayer.open(title,content,width, height)
        },
        /**
         * 编辑
         * @param options
         */
        opneEdit:function(options){
            var opts = options,
                title=opts.title||"编辑",
                url=opts.url,
                value=opts.value,
                width=opts.width||"90%",
                height=opts.height||"90%",
                content=url+"?id="+value+"&op=edit";
            console.log(url);
            openLayer.open(title,content,width, height);
        },
        /**
         * 添加
         * @param options
         */
        opneAdd:function(options){
            var opts = options,
                title=opts.title||"添加",
                url=opts.url,
                width=opts.width||"90%",
                height=opts.height||"90%",
                content=url+"?op=add";
            openLayer.open(title,content,width, height);
        },
            /**
             * 添加
             * @param options
             */
            opneAddNext:function(options){
                var opts = options,
                    title=opts.title||"添加",
                    url=opts.url,
                    value=opts.value,
                    width=opts.width||"90%",
                    height=opts.height||"90%",
                    content=url+"?parent.id=" + value+"&op=add";
                openLayer.open(title,content,width, height);
            },

        /**
         * open()函数二次封装
         * @param title
         * @param content
         * @param width
         */
        open: function (title, content,width, height) {
            layer.open({
                title: title,
                type: 2,
                isOutAnim:true,
                maxmin: true,
                shade: 0.5,
                anim: "0",
                area: [width, height],
                content: content,
                zIndex: layer.zIndex,
                skin: "1"
            });
        },

            // msg弹窗默认消失时间
            successtime: 1000,
            // msg弹窗默认消失时间
            errortime: 3000,
        // 绿色勾
        greenTickMsg: function (content, callbackFunction) {
            let options = {icon: 1, time: openLayer.successtime, anim: "0"};
            layer.msg(content, options, callbackFunction);
        },
        // 红色叉
        redCrossMsg: function (content, callbackFunction) {
            let options = {icon: 2, time: openLayer.errortime, anim: "0"};
            layer.msg(content, options, callbackFunction);
        },
        // 黄色问号
        yellowQuestionMsg: function (content, callbackFunction) {
            let options = {icon: 3, time: openLayer.time, anim: "0"};
            layer.msg(content, options, callbackFunction);
        },
        // 灰色锁
        grayLockMsg: function (content, callbackFunction) {
            let options = {icon: 4, time: openLayer.time, anim: "0"};
            layer.msg(content, options, callbackFunction);
            openLayer.close();
        },
        // 红色哭脸
        redCryMsg: function (content, callbackFunction) {
            let options = {icon: 5, time: openLayer.time, anim: "0"};
            layer.msg(content, options, callbackFunction);
        },
        // 绿色笑脸
        greenLaughMsg: function (content, callbackFunction) {
            let options = {icon: 6, time: openLayer.time, anim: "0"};
            layer.msg(content, options, callbackFunction);
        },
        // 黄色感叹号
        yellowSighMsg: function (content, callbackFunction) {
            let options = {icon: 7, time: openLayer.errortime, anim: "0"};
            layer.msg(content, options, callbackFunction);
        },

            //消息弹窗
        popup:function(content){
            if(content.code==msgType.success){
                //成功
                openLayer.greenTickMsg(content.msg, function () {
                    openLayer.close();
                });
            }else if (content.code==msgType.fail) {
                //失败
                openLayer.redCrossMsg(content.msg, function () {
                    openLayer.close();
                });
            } else if(content.code==msgType.custom){
                //自定义
                openLayer.redCrossMsg(content.msg, function () {
                    openLayer.close();
                });
            }else {
                openLayer.redCrossMsg(content.msg, function () {
                    //openLayer.close();
                });
            }

        },

            //关闭刷新
         close:function () {
             var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
             parent.window.location.reload();//刷新父页面，
             parent.layer.close(index);//执行关闭

         },
            //刷新
        refresh:function () {
            $(".layui-tab-item.layui-show").find("iframe")[0].contentWindow.location.reload();
        }

    };
    //关闭按钮事件
    $("#btnclose").on("click", function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);//关闭当前页
    });

    exports("openLayer", openLayer);
});
